import time
from datetime import datetime, timedelta

from typing import List, Optional

import uvicorn
import os
import config
from fastapi import Depends, FastAPI, HTTPException, Security, status, UploadFile, File

app = FastAPI()


# 上传文件
async def upload_file(file: UploadFile):
    connent = await file.read()
    file_name = '/user/' + str(time.time()) + 'jpg'
    path = '/Users/apple/Desktop/学习/fastapi-self/ststic'
    file_path = os.path.join(path, file_name)
    # with open(file_path, 'rb') as f:
    #     f.write(connent)
    return file_path


@app.post('/user/file_upload', name='上传文件')
async def upload_file_view(file: UploadFile = File(...)):
    file_path = upload_file(file)
    return file_path





if __name__ == "__main__":
    uvicorn.run(app='upload_file:app', host='0.0.0.0', port=8089, reload=True, debug=True, workers=1)